{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9a39ba93",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d8f35f55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[ 0,  1,  2,  3,  4],\n",
       "        [ 5,  6,  7,  8,  9],\n",
       "        [10, 11, 12, 13, 14],\n",
       "        [15, 16, 17, 18, 19]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.arange(0,20).view(-1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "93c1a000",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[ 0,  1,  2,  3,  4],\n",
       "         [ 5,  6,  7,  8,  9]],\n",
       "\n",
       "        [[10, 11, 12, 13, 14],\n",
       "         [15, 16, 17, 18, 19]]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1 = torch.arange(0,20).view(2,2,5)\n",
    "d1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "80f6277a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[ 0,  5],\n",
       "         [ 1,  6],\n",
       "         [ 2,  7],\n",
       "         [ 3,  8],\n",
       "         [ 4,  9]],\n",
       "\n",
       "        [[10, 15],\n",
       "         [11, 16],\n",
       "         [12, 17],\n",
       "         [13, 18],\n",
       "         [14, 19]]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# transpose\n",
    "d1.transpose(1,2)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fabbac48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[-0.3330, -1.9937, -0.7599, -0.3849,  0.1420],\n",
       "          [ 1.0095,  1.2680,  1.0740, -0.0731, -0.3207],\n",
       "          [-0.0400, -0.8292, -1.4843, -0.7386, -0.4131],\n",
       "          [-1.0271,  0.9586, -0.4206,  1.3476,  0.6680]],\n",
       "\n",
       "         [[ 0.3954, -0.0441,  1.6563, -0.1633,  1.7637],\n",
       "          [-1.4800,  0.2845,  0.0911, -1.5298,  0.0614],\n",
       "          [-0.1182,  0.6735,  0.7072, -1.2930, -0.1079],\n",
       "          [ 1.1638, -0.0627, -1.2331,  0.5457,  1.1323]],\n",
       "\n",
       "         [[-0.5848, -0.4471, -0.3861,  0.9356, -0.1692],\n",
       "          [-1.1667, -0.4201,  0.6145,  0.5500,  0.0627],\n",
       "          [-0.2089, -0.4632,  0.2421, -3.4281,  0.9421],\n",
       "          [-0.7527,  1.8345,  0.4216, -1.5778, -0.6367]]],\n",
       "\n",
       "\n",
       "        [[[ 0.9495,  0.4169, -1.4190, -0.9949,  0.0843],\n",
       "          [-1.3034, -0.3049, -0.5938,  1.3212,  1.2053],\n",
       "          [ 0.7689,  0.8460,  0.0903, -1.4761, -0.2862],\n",
       "          [ 0.1876, -0.2865, -0.2986,  0.2127,  0.1950]],\n",
       "\n",
       "         [[ 0.9068,  0.8125,  1.9050,  0.5786, -1.1665],\n",
       "          [-0.5053, -0.7779, -0.6505,  0.2642,  1.7281],\n",
       "          [ 0.3493, -2.0572,  0.4136,  0.5870,  0.2450],\n",
       "          [ 1.6324, -1.2962, -0.3695, -0.2156,  1.1184]],\n",
       "\n",
       "         [[-1.3115,  0.4541, -0.0917, -0.1053,  0.8459],\n",
       "          [-0.7306, -0.1391,  0.7882, -0.2477,  0.4406],\n",
       "          [ 0.8871, -0.7856, -0.7058, -0.6776, -1.3556],\n",
       "          [ 0.4450, -1.3407, -0.6288,  0.4335,  0.5526]]]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2=torch.randn(2,3,4,5)\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3bc75918",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'd2' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[3], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43md2\u001b[49m   \u001b[38;5;66;03m# [2,3,4,5]\u001b[39;00m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'd2' is not defined"
     ]
    }
   ],
   "source": [
    "d2   # [2,3,4,5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "b883c58e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[-0.4646, -0.2345,  1.1541,  0.1558, -0.0805],\n",
       "          [-0.8970,  0.3725,  1.4625, -0.5846,  0.4867],\n",
       "          [-0.0257, -1.3697, -0.7496,  0.9702,  0.1298],\n",
       "          [ 0.2136, -0.8272, -1.3418, -1.1765,  1.1456]],\n",
       "\n",
       "         [[ 0.5391,  0.0690, -0.4760, -0.0620, -1.6533],\n",
       "          [ 2.1552, -1.3146, -0.1238,  0.0508, -0.2212],\n",
       "          [ 0.1566,  1.0955, -0.1120, -0.9290,  0.0804],\n",
       "          [ 1.6599,  0.0819,  0.1441,  1.2844, -0.5016]]],\n",
       "\n",
       "\n",
       "        [[[-1.6973,  1.0093, -0.9638,  0.3128, -0.7029],\n",
       "          [ 1.1877,  0.1584, -0.8434,  1.2862,  0.2293],\n",
       "          [ 0.1476,  1.3694, -0.9507, -0.3082,  1.2235],\n",
       "          [-0.9242,  0.3935,  1.3028,  2.3808,  0.2035]],\n",
       "\n",
       "         [[-1.1832,  0.7721,  2.7105, -0.8383,  0.2189],\n",
       "          [-2.1778,  0.3442, -0.8926,  0.4717, -0.7230],\n",
       "          [ 0.2429,  0.0720,  0.6215, -0.1328, -0.0423],\n",
       "          [ 1.4607,  0.4600,  1.1580, -0.1895,  0.0487]]],\n",
       "\n",
       "\n",
       "        [[[-0.0830, -0.4125,  0.9109, -0.5751,  1.0010],\n",
       "          [-1.0537,  0.3526,  0.0907,  0.2875, -0.5189],\n",
       "          [ 1.0062, -1.5030, -0.9421, -0.5690, -0.9186],\n",
       "          [ 1.0324, -0.9147,  2.1096,  0.8058, -0.8457]],\n",
       "\n",
       "         [[-0.7945, -1.4550,  0.9755,  0.9024,  0.7177],\n",
       "          [-0.3083, -0.4453,  0.9609, -0.9726, -2.0207],\n",
       "          [-0.3950,  0.1006, -1.5891, -0.9674,  0.0414],\n",
       "          [-0.9456, -0.3907,  1.0619, -0.8223, -0.3304]]]])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2.transpose(0,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "f487ce83",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[ 0.5342,  1.6554,  1.9479, -0.2518],\n",
       "          [ 1.2367, -0.6041, -0.9379,  0.9220],\n",
       "          [ 0.8342, -1.8203,  0.4609, -0.2718],\n",
       "          [ 0.1579,  0.2972, -0.3704, -0.8503],\n",
       "          [ 1.0601, -0.4388,  1.0110, -0.0156]],\n",
       "\n",
       "         [[-2.0826, -0.0496, -0.2885, -0.5293],\n",
       "          [-0.9590, -0.2745,  0.1516,  0.2973],\n",
       "          [-0.3692,  0.9743, -0.9401, -0.6294],\n",
       "          [ 0.3898, -1.1989,  0.3937,  0.9207],\n",
       "          [ 0.4788,  1.6122,  0.8851,  0.5225]],\n",
       "\n",
       "         [[ 0.0793,  1.3958, -0.4574,  0.9894],\n",
       "          [-0.0147, -0.2198,  1.1638,  0.2982],\n",
       "          [ 0.3255,  1.9409,  1.7178, -0.1845],\n",
       "          [ 0.5797,  0.8564, -0.9505,  1.0810],\n",
       "          [-0.7911, -1.1213,  0.5418,  0.6956]]],\n",
       "\n",
       "\n",
       "        [[[ 0.7603,  0.3253,  2.4617,  0.6806],\n",
       "          [ 0.6205, -0.4465,  0.6274,  1.4742],\n",
       "          [-0.7940, -0.3416,  1.2478,  0.2757],\n",
       "          [-0.5725, -1.3107, -0.2536,  0.4839],\n",
       "          [ 0.6978,  1.1703, -1.8765, -0.7823]],\n",
       "\n",
       "         [[ 0.2562, -0.1364, -0.3601,  0.4908],\n",
       "          [-0.8829,  2.5672,  1.1364, -0.1939],\n",
       "          [-1.2998, -0.2433,  0.6155, -1.0154],\n",
       "          [-1.5316, -0.8702, -0.4513, -1.1627],\n",
       "          [-0.4179,  0.5507, -0.1790,  0.4302]],\n",
       "\n",
       "         [[ 0.7753, -0.8354,  1.5354, -0.1450],\n",
       "          [ 0.6966, -0.0249, -1.9947,  0.4267],\n",
       "          [-0.0543, -0.8421,  0.9063, -0.2299],\n",
       "          [ 1.1899,  0.7270,  0.3073,  0.3465],\n",
       "          [-1.1236,  0.0782, -0.1799,  1.7888]]]])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2.transpose(2,3)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1b522412",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[-0.3330, -1.9937, -0.7599, -0.3849,  0.1420],\n",
       "          [ 1.0095,  1.2680,  1.0740, -0.0731, -0.3207],\n",
       "          [-0.0400, -0.8292, -1.4843, -0.7386, -0.4131],\n",
       "          [-1.0271,  0.9586, -0.4206,  1.3476,  0.6680]],\n",
       "\n",
       "         [[ 0.3954, -0.0441,  1.6563, -0.1633,  1.7637],\n",
       "          [-1.4800,  0.2845,  0.0911, -1.5298,  0.0614],\n",
       "          [-0.1182,  0.6735,  0.7072, -1.2930, -0.1079],\n",
       "          [ 1.1638, -0.0627, -1.2331,  0.5457,  1.1323]],\n",
       "\n",
       "         [[-0.5848, -0.4471, -0.3861,  0.9356, -0.1692],\n",
       "          [-1.1667, -0.4201,  0.6145,  0.5500,  0.0627],\n",
       "          [-0.2089, -0.4632,  0.2421, -3.4281,  0.9421],\n",
       "          [-0.7527,  1.8345,  0.4216, -1.5778, -0.6367]]],\n",
       "\n",
       "\n",
       "        [[[ 0.9495,  0.4169, -1.4190, -0.9949,  0.0843],\n",
       "          [-1.3034, -0.3049, -0.5938,  1.3212,  1.2053],\n",
       "          [ 0.7689,  0.8460,  0.0903, -1.4761, -0.2862],\n",
       "          [ 0.1876, -0.2865, -0.2986,  0.2127,  0.1950]],\n",
       "\n",
       "         [[ 0.9068,  0.8125,  1.9050,  0.5786, -1.1665],\n",
       "          [-0.5053, -0.7779, -0.6505,  0.2642,  1.7281],\n",
       "          [ 0.3493, -2.0572,  0.4136,  0.5870,  0.2450],\n",
       "          [ 1.6324, -1.2962, -0.3695, -0.2156,  1.1184]],\n",
       "\n",
       "         [[-1.3115,  0.4541, -0.0917, -0.1053,  0.8459],\n",
       "          [-0.7306, -0.1391,  0.7882, -0.2477,  0.4406],\n",
       "          [ 0.8871, -0.7856, -0.7058, -0.6776, -1.3556],\n",
       "          [ 0.4450, -1.3407, -0.6288,  0.4335,  0.5526]]]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ab9b73c7",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'd2' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[2], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43md2\u001b[49m\u001b[38;5;241m.\u001b[39mtranspose(\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'd2' is not defined"
     ]
    }
   ],
   "source": [
    "d2.transpose(1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "066660f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[ 0.1170,  1.2222, -0.8566,  1.0779, -1.4076],\n",
       "          [-2.6009,  0.8215, -0.0290,  0.1987, -1.9521],\n",
       "          [-1.8133, -0.4488,  0.0801,  0.2330,  1.8614],\n",
       "          [ 1.8678,  1.4364,  0.7055, -1.7607,  1.1073]],\n",
       "\n",
       "         [[-0.1657, -0.3754,  1.1800,  0.3803, -0.2249],\n",
       "          [ 0.5189, -0.7892,  1.3388,  0.1342, -1.3712],\n",
       "          [-0.8063, -0.3620, -0.3241, -0.9368, -1.2954],\n",
       "          [-0.4713, -0.0693, -2.6252,  1.3872,  0.9932]],\n",
       "\n",
       "         [[ 0.3480, -1.0171, -0.6426, -0.0858,  0.8177],\n",
       "          [ 0.2132, -0.0577,  0.0511, -0.9108,  0.3383],\n",
       "          [-0.6454,  0.7822, -2.7153, -0.5527,  0.0244],\n",
       "          [ 1.6133, -0.2542, -0.5668, -1.2247,  0.9130]]],\n",
       "\n",
       "\n",
       "        [[[ 1.2561, -0.1256, -0.2374,  0.9345,  0.6568],\n",
       "          [-0.3125, -0.1313, -0.2199, -0.1808,  0.1650],\n",
       "          [ 0.8395, -0.5217, -1.2980,  0.6799, -2.0816],\n",
       "          [-0.8129, -0.4923, -0.2940,  1.0424, -0.5239]],\n",
       "\n",
       "         [[ 0.7150,  0.3261, -0.2283,  0.0375, -0.3431],\n",
       "          [-0.0320,  0.3060,  0.9930, -0.2339,  0.6793],\n",
       "          [ 1.8039,  0.4455, -0.2595, -0.7351,  2.0017],\n",
       "          [-1.6560,  1.3897, -0.0530,  0.1160, -1.6537]],\n",
       "\n",
       "         [[ 1.1025,  0.3267,  0.6012,  0.7567,  0.1239],\n",
       "          [ 1.0182, -0.3042,  0.5954, -0.0225,  0.2996],\n",
       "          [ 0.1608,  0.6988, -1.0478,  0.4754,  0.7178],\n",
       "          [-0.7552,  0.0613, -1.1202,  0.3665, -0.1013]]]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1=torch.randn(2,3,4,5)\n",
    "d1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f4d6975a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor(-0.0140)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "39f9d3b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "torch.Size([2, 3, 4, 5])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1.size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3d31bcc6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[ 0.1170,  1.2222, -0.8566,  1.0779, -1.4076],\n",
       "          [-2.6009,  0.8215, -0.0290,  0.1987, -1.9521],\n",
       "          [-1.8133, -0.4488,  0.0801,  0.2330,  1.8614],\n",
       "          [ 1.8678,  1.4364,  0.7055, -1.7607,  1.1073]],\n",
       "\n",
       "         [[-0.1657, -0.3754,  1.1800,  0.3803, -0.2249],\n",
       "          [ 0.5189, -0.7892,  1.3388,  0.1342, -1.3712],\n",
       "          [-0.8063, -0.3620, -0.3241, -0.9368, -1.2954],\n",
       "          [-0.4713, -0.0693, -2.6252,  1.3872,  0.9932]],\n",
       "\n",
       "         [[ 0.3480, -1.0171, -0.6426, -0.0858,  0.8177],\n",
       "          [ 0.2132, -0.0577,  0.0511, -0.9108,  0.3383],\n",
       "          [-0.6454,  0.7822, -2.7153, -0.5527,  0.0244],\n",
       "          [ 1.6133, -0.2542, -0.5668, -1.2247,  0.9130]]],\n",
       "\n",
       "\n",
       "        [[[ 1.2561, -0.1256, -0.2374,  0.9345,  0.6568],\n",
       "          [-0.3125, -0.1313, -0.2199, -0.1808,  0.1650],\n",
       "          [ 0.8395, -0.5217, -1.2980,  0.6799, -2.0816],\n",
       "          [-0.8129, -0.4923, -0.2940,  1.0424, -0.5239]],\n",
       "\n",
       "         [[ 0.7150,  0.3261, -0.2283,  0.0375, -0.3431],\n",
       "          [-0.0320,  0.3060,  0.9930, -0.2339,  0.6793],\n",
       "          [ 1.8039,  0.4455, -0.2595, -0.7351,  2.0017],\n",
       "          [-1.6560,  1.3897, -0.0530,  0.1160, -1.6537]],\n",
       "\n",
       "         [[ 1.1025,  0.3267,  0.6012,  0.7567,  0.1239],\n",
       "          [ 1.0182, -0.3042,  0.5954, -0.0225,  0.2996],\n",
       "          [ 0.1608,  0.6988, -1.0478,  0.4754,  0.7178],\n",
       "          [-0.7552,  0.0613, -1.1202,  0.3665, -0.1013]]]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "348f1c5a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.]],\n",
       "\n",
       "         [[1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.]],\n",
       "\n",
       "         [[1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.]]],\n",
       "\n",
       "\n",
       "        [[[1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.]],\n",
       "\n",
       "         [[1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.]],\n",
       "\n",
       "         [[1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.],\n",
       "          [1., 1., 1., 1.]]]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d2=torch.ones(2,3,5,4)\n",
    "d2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0c6820b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[[ 0.1530,  0.1530,  0.1530,  0.1530],\n",
       "          [-3.5618, -3.5618, -3.5618, -3.5618],\n",
       "          [-0.0876, -0.0876, -0.0876, -0.0876],\n",
       "          [ 3.3564,  3.3564,  3.3564,  3.3564]],\n",
       "\n",
       "         [[ 0.7944,  0.7944,  0.7944,  0.7944],\n",
       "          [-0.1685, -0.1685, -0.1685, -0.1685],\n",
       "          [-3.7246, -3.7246, -3.7246, -3.7246],\n",
       "          [-0.7853, -0.7853, -0.7853, -0.7853]],\n",
       "\n",
       "         [[-0.5798, -0.5798, -0.5798, -0.5798],\n",
       "          [-0.3659, -0.3659, -0.3659, -0.3659],\n",
       "          [-3.1068, -3.1068, -3.1068, -3.1068],\n",
       "          [ 0.4805,  0.4805,  0.4805,  0.4805]]],\n",
       "\n",
       "\n",
       "        [[[ 2.4845,  2.4845,  2.4845,  2.4845],\n",
       "          [-0.6794, -0.6794, -0.6794, -0.6794],\n",
       "          [-2.3820, -2.3820, -2.3820, -2.3820],\n",
       "          [-1.0807, -1.0807, -1.0807, -1.0807]],\n",
       "\n",
       "         [[ 0.5072,  0.5072,  0.5072,  0.5072],\n",
       "          [ 1.7124,  1.7124,  1.7124,  1.7124],\n",
       "          [ 3.2565,  3.2565,  3.2565,  3.2565],\n",
       "          [-1.8570, -1.8570, -1.8570, -1.8570]],\n",
       "\n",
       "         [[ 2.9111,  2.9111,  2.9111,  2.9111],\n",
       "          [ 1.5865,  1.5865,  1.5865,  1.5865],\n",
       "          [ 1.0050,  1.0050,  1.0050,  1.0050],\n",
       "          [-1.5488, -1.5488, -1.5488, -1.5488]]]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "torch.matmul(d1,d2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "f713847b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[[ 0.1530, -3.5618, -0.0876,  3.3564],\n",
       "         [ 0.7944, -0.1685, -3.7246, -0.7853],\n",
       "         [-0.5798, -0.3659, -3.1068,  0.4805]],\n",
       "\n",
       "        [[ 2.4845, -0.6794, -2.3820, -1.0807],\n",
       "         [ 0.5072,  1.7124,  3.2565, -1.8570],\n",
       "         [ 2.9111,  1.5865,  1.0050, -1.5488]]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d1.sum(-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3c65a15b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.15290000000000004"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0.1170+1.2222+-0.8566+1.0779+-1.4076"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0cd9e91e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8318df95",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a091d702",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "torch11.3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
